package it.unina.lusi;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.google.android.maps.MapView.ReticleDrawMode;

public class BasicMapAppActivity extends MapActivity {
	
	private List<Overlay> mapOverlays;
	private MapController mc; 
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        
 
        
        mc = mapView.getController();
        Geocoder geocod = new Geocoder(getApplicationContext());
        List<Address> indirizzi = new LinkedList<Address>();
		try {
			indirizzi = geocod.getFromLocationName("Via Epomeo 54, Napoli", 2);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        GeoPoint p = new GeoPoint((int) (indirizzi.get(0).getLatitude() * 1E6), (int) (indirizzi.get(0).getLongitude() * 1E6));
        
        mc.animateTo(p);
        mc.setZoom(20);
//        Point myPoint = new Point();
//        Projection proj = mapView.getProjection();
//        proj.toPixels(p, myPoint);
//        Toast.makeText(this, "Point x=" + myPoint.x +"  ,  y= " + myPoint.y, Toast.LENGTH_LONG).show();
        
        
        mapOverlays = mapView.getOverlays();
        MyOverlay myOverlay = new MyOverlay(mapView, getBaseContext());
        mapOverlays.add(myOverlay);
    
       
       
    }
 
  
    
    
    
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
}